from src import Preproduction as Pre

id, ch = Pre.load("results/hanzi_2_one_hot.data")
cnt = len(ch)
V = 10000

print("cnt = " + str(cnt))
print("V = " + str(V))

from src.EmbeddingGloVe import genX as genX
from src.EmbeddingGloVe import Glove as Glove

pathBase = 'dataset/chat_corpus/clean_chat_corpus/'
paths = [
    "chatterbot.tsv",
    "douban_single_turn.tsv",
    "ptt.tsv",
    "qingyun.tsv",
    "subtitle.tsv",
    "tieba.tsv",
    "weibo.tsv"
]
fullPaths = [pathBase + path for path in paths]

import numpy as np
import random

from src.GeneratorLSTMv9 import LSTM

embDim = 128
hidDim = 512
seqLen = 30

lstm = LSTM(embDim, hidDim, V)
lstm.load("results/V9LSTM050.model")

def Gen(cur):
    x = [id[i] if id[i] < V else 0 for i in cur]
    e = lstm.eval(x)
    res = ''
    for i in e:
        res += ch[i] if i > 1 else ''
    return res
    

def handle(conf):
    """
    该方法是部署之后，其他人调用你的服务时候的处理方法。
    请按规范填写参数结构，这样我们就能替你自动生成配置文件，方便其他人的调用。
    范例：
    params['key'] = value # value_type: str # description: some description
    value_type 可以选择：img, video, audio, str, int, float, [int], [str], [float]
    参数请放到params字典中，我们会自动解析该变量。
    """

    cur = conf['request']  # value_type: str # description: The sentence to speak to the model
    
    # add your code
    return {'response': Gen(cur)}
    